package com.cars.bim.generator.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import com.cars.bim.generator.dao.TbKaoqinDao;
import com.cars.bim.generator.entity.TbKaoqinEntity;
import com.cars.bim.generator.service.TbKaoqinService;
import com.cars.framework.modules.sys.dao.SysUserDao;
import com.cars.framework.modules.sys.entity.SysUserEntity;



@Service("tbKaoqinService")
public class TbKaoqinServiceImpl implements TbKaoqinService {
	@Autowired
	private TbKaoqinDao tbKaoqinDao;
	@Autowired
	private  SysUserDao sysUserDao;
	
	@Override
	public TbKaoqinEntity queryObject(Integer id){
		return tbKaoqinDao.queryObject(id);
	}
	
	@Override
	public List<TbKaoqinEntity> queryList(Map<String, Object> map){
		return tbKaoqinDao.queryList(map);
	}
	
	@Override
	public int queryTotal(Map<String, Object> map){
		return tbKaoqinDao.queryTotal(map);
	}
	
	@Override
	public void save(TbKaoqinEntity tbKaoqin){
		SysUserEntity sysUser = sysUserDao.queryByUserName(tbKaoqin.getUsername());
		double  gongzi = Double.parseDouble(sysUser.getGongzi());
		double chuqin =  Double.parseDouble(tbKaoqin.getChuqin());
		if(chuqin!= 22){
			gongzi = (gongzi/22)*chuqin;
		}
		String qingjia = tbKaoqin.getQingjia();
		double chidaototal = Double.parseDouble(tbKaoqin.getChidao())*20; //迟到20
		double jiabantotal = Double.parseDouble(tbKaoqin.getNianxiu())*20; //加班20
		
		double qingjiatotal = Double.parseDouble(qingjia)*100; //一天扣100
		double  g= gongzi-chidaototal-qingjiatotal+jiabantotal;
		String total = g+"";
		tbKaoqin.setCreateDate(total);
		tbKaoqinDao.save(tbKaoqin);
	}
	
	@Override
	public void update(TbKaoqinEntity tbKaoqin){
		SysUserEntity sysUser = sysUserDao.queryByUserName(tbKaoqin.getUsername());
		double  gongzi = Double.parseDouble(sysUser.getGongzi());
		double chuqin =  Double.parseDouble(tbKaoqin.getChuqin());
		if(chuqin!= 22){
			gongzi = (gongzi/22)*chuqin;
		}
		String qingjia = tbKaoqin.getQingjia();
		double chidaototal = Double.parseDouble(tbKaoqin.getChidao())*20; //迟到20
		double jiabantotal = Double.parseDouble(tbKaoqin.getNianxiu())*20; //加班20
		
		double qingjiatotal = Double.parseDouble(qingjia)*100; //一天扣100
		double  g= gongzi-chidaototal-qingjiatotal+jiabantotal;
		String total = g+"";
		tbKaoqin.setCreateDate(total);
		tbKaoqinDao.update(tbKaoqin);
	}
	
	@Override
	public void delete(Integer id){
		tbKaoqinDao.delete(id);
	}
	
	@Override
	public void deleteBatch(Integer[] ids){
		tbKaoqinDao.deleteBatch(ids);
	}
	
}
